import type { Executor } from '../';
import type { UserDto } from '../model/dto';
import type { PageParam, PageResult, UserInput, UserSpecification } from '../model/static';

export class UserController {
    
    constructor(private executor: Executor) {}
    
    async add(options: UserControllerOptions['add']): Promise<void> {
        let _uri = '/user/add';
        return (await this.executor({uri: _uri, method: 'POST', body: options.body})) as void
    }
    
    async deleteByIds(options: UserControllerOptions['deleteByIds']): Promise<void> {
        let _uri = '/user/deleteByIds';
        return (await this.executor({uri: _uri, method: 'POST', body: options.body})) as void
    }
    
    async page(options: UserControllerOptions['page']): Promise<
        PageResult<UserDto['UserShape/PASSWORD_LESS_WITH_ROLE_IDS']>
    > {
        let _uri = '/user/page';
        let _separator = _uri.indexOf('?') === -1 ? '?' : '&';
        let _value: any = undefined;
        _value = options.pageParam.currentPage;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'currentPage='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.pageParam.pageSize;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'pageSize='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.avatar;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'avatar='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.createTime;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'createTime='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.email;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'email='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.id;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'id='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.mobile;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'mobile='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.nickname;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'nickname='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.password;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'password='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.updateTime;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'updateTime='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        _value = options.specification.username;
        if (_value !== undefined && _value !== null) {
            _uri += _separator
            _uri += 'username='
            _uri += encodeURIComponent(_value);
            _separator = '&';
        }
        return (await this.executor({uri: _uri, method: 'GET'})) as PageResult<UserDto['UserShape/PASSWORD_LESS_WITH_ROLE_IDS']>
    }
    
    async update(options: UserControllerOptions['update']): Promise<void> {
        let _uri = '/user/update';
        return (await this.executor({uri: _uri, method: 'POST', body: options.body})) as void
    }
    
    async userInfo(): Promise<
        UserDto['UserShape/PASSWORD_LESS']
    > {
        let _uri = '/user/userInfo';
        return (await this.executor({uri: _uri, method: 'GET'})) as UserDto['UserShape/PASSWORD_LESS']
    }
}

export type UserControllerOptions = {
    'add': {readonly body: UserInput},
    'deleteByIds': {readonly body: ReadonlyArray<number>},
    'page': {readonly pageParam: PageParam, readonly specification: UserSpecification},
    'update': {readonly body: UserInput},
    'userInfo': {}
}